 package fy.erp.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.apache.commons.logging.LogFactory;

import fy.config.FyConfig;
import fy.util.DBUtil;

public class NewClientDao {
	private static org.apache.commons.logging.Log log = LogFactory
			.getLog(NewClientDao.class);
	private static final String ERPINSERTSQL = "insert into apps.FYG_PO_UAP_VENDORS@"
			+ FyConfig.getERP_DB_CONFIG().getDblink()
			+ "(VENDORS_NUM, VENDORS_NAME, SYB, UAPLB, ZT, flag) values ( ?,?,(select c.unitname from bd_corp c where c.pk_corp = ? and rownum = 1),'客户','客户','Y')  ";
	private String clientName;
	private String clientCode;
	private String corp;
	private String number;

	public void setNumber(String number) {
		this.number = number;
	}

	public void setClientName(String clientName) {
		this.clientName = clientName;
	}

	public void setClientCode(String clientCode) {
		this.clientCode = clientCode;
	}

	public void setCorp(String corp) {
		this.corp = corp;
	}

	public boolean save() {
		boolean success = false;

		Connection conn = null;
		PreparedStatement pst = null;

		try {

			conn = DBUtil.connect(FyConfig.getUAP_DB_CONFIG());

			pst = conn.prepareStatement(ERPINSERTSQL);

			pst.setString(1, clientCode);
			pst.setString(2, clientName);
			pst.setString(3, corp);

			pst.execute();

			success = true;

		} catch (Exception e) {
			success = false;
			e.printStackTrace();
			log.error("《新客户授信申请表》导入UPA异常，单据编号：" + number, e);
		} finally {
			DBUtil.close(pst, conn);
		}
		return success;
	}
}
